package com.fxm.controller;

import com.fxm.returns.RespEntity;
import com.fxm.returns.RespTable;
import com.fxm.service.QuestionService;
import com.fxm.vo.param.QuestionParam;
import com.fxm.vo.result.QuestionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 题目管理 前端控制器
 * </p>
 *
 * @author fxm
 * @since 2021-02-20
 */
@RestController
@RequestMapping("/question")
@Slf4j
@Api(value = "题目管理", tags = "题目管理")
public class QuestionController {

    @Resource
    private QuestionService questionService;

    @GetMapping("/list")
    @ApiOperation(value = "题目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "questionTitle", value = "题目名称", required = false)
    })
    public RespTable<List<QuestionResult>> questionList(@RequestParam(value = "page", required = true) Integer page,
                                                        @RequestParam(value = "limit", required = true) Integer limit,
                                                        @RequestParam(value = "questionTitle", required = false) String questionTitle) {
        RespTable<List<QuestionResult>> respTable = questionService.questionList(page, limit, questionTitle);
        return respTable;
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加题目")
    public RespEntity insertQuestion(@RequestBody QuestionParam questionParam) {
        RespEntity respEntity = questionService.insertQuestion(questionParam);
        return respEntity;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑题目")
    public RespEntity updateQuestion(@RequestBody QuestionParam questionParam) {
        RespEntity respEntity = questionService.updateQuestion(questionParam);
        return respEntity;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除题目")
    public RespEntity deleteQuestion(@RequestParam(value = "id", required = true) Integer id) {
        RespEntity respEntity = questionService.deleteQuestion(id);
        return respEntity;
    }

    @DeleteMapping("/batchDelete")
    @ApiOperation(value = "批量删除题目")
    public RespEntity batchDeleteQuestion(@RequestParam(value = "ids", required = true) Integer[] ids) {
        RespEntity respEntity = questionService.batchDeleteQuestion(ids);
        return respEntity;
    }

}
